

<template>
    <div class="storeInfo">
        <div class="head">
            <el-form :model="form" class="headForm">
                <!-- <el-form-item>
                    <el-select clearable v-model="form.category_id" placeholder="商品分类">
                        <el-option v-for="item in catelist" :key="item.category_id" :label="item.cate_name" :value="item.category_id"></el-option>
                    </el-select>
                </el-form-item>   -->
                <el-form-item>
                    <el-input placeholder="商品名称" v-model="form.product_name"></el-input>
                </el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                <el-button type="success" @click="theClick('add')">添加</el-button>


            </el-form>
            
        </div>
        <!-- <p style="line-height:30px;padding-left:20px;margin-top:8px;color:#333" v-if="form.order_id == ''">最近{{total}}笔人工退款订单记录</p> -->
        <!-- table -->
        <div class="tabContainer">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center" >
                <!--合同编号	所属区域	城市	品牌授权位置	签约日期	合同期限	录入时间	项目名称	操作人			 -->
                <el-table-column prop="contract_no" label="合同编号" fixed ></el-table-column>
                <el-table-column prop="area_name" label="所属区域"></el-table-column>
                <el-table-column prop="city_name" label="城市" > </el-table-column>
                <el-table-column prop="authorize_address" label="品牌授权位置" ></el-table-column>

                  
                <el-table-column prop="limitation" label="签约日期" width="180px"></el-table-column>
                <el-table-column prop="contract_deadline" label="合同期限"></el-table-column>
                <el-table-column prop="create_time" label="录入时间" width="180px"></el-table-column>
                <el-table-column prop="" label="项目名称"  width="200px">
                    <template slot-scope="scope">
                        <p v-if="scope.row.project_title != null">{{scope.row.project_title}}</p>
                        <p v-else @click="theClick(scope.row,'relative')" style="color:#409EFF;cursor:pointer">关联项目</p>
                    </template>
                </el-table-column>
                <el-table-column prop="" label="操作人">
                    <template slot-scope="scope">
                        <p @click="theClick(scope.row,'detail')" style="color:#409EFF;cursor:pointer">详情</p>
                    </template>
                </el-table-column>

            </el-table>                       
        </div>
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>

        <el-dialog title="关联项目" :visible.sync="add_edit_show" class="business">
            <el-form ref="form" :model="editForm" label-width="120px">
                <el-form-item label="关联项目">
                    <searchList :input_url="url" v-on:getsearchItemGood="getitem"></searchList>
                    <!-- <el-input v-model="editForm.product_name"></el-input>            -->
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="add_edit_show = false">取 消</el-button>
                <el-button type="primary" @click="confrim">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<style lang="scss">
.supplier{
        .el-dialog{
            .el-dialog__body{
                min-height: 300px;
            }
        } 
    }
  .tabContainer_SI{
      .el-table{
          .cell{
              text-align: center;
          }
      }
  }
</style>

<script>
import Vue from 'vue';
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js'; 
import searchList from '../../pop/goodslist.vue'

export default {
    components:{
        searchList
    },
    data () {
    return {
        tableData:[],
        total:50,
        size:20,
        form:{size:20,
            page:1
        },
        pageNum:1,
        url:potUrl.contractsearch,
        add_edit_show:false,
        editForm:{},
        

    }
  }, 
   mounted(){
      let that = this;
      that.getList();
      abc.get(that,potUrl.categoryList,{},res=>{
          that.catelist = res.data
      })
  },
  methods:{
    search(){
        let that = this;
        console.log(that.timerange)
        if(that.timerange.length > 0){
            that.form.start_time  = that.timerange[0]
            that.form.end_time  = that.timerange[1]
        }
        that.getList()
    },
    changePage(val){
        var that = this;
        that.pageNum = val;
        that.form.page = val;
        that.getList()
    },
    getList(){
        let that = this;
        abc.get(that,potUrl.contactlist,that.form,(res)=>{
            that.tableData=res.data.list;
            that.total = res.data.total;
        })//列表
    },
    confrim(a){
        const that = this;
        that.add_edit_show = false;
        
        abc.post(that,potUrl.contractrelation,that.editForm,(res)=>{
            that.getList()
        })
    },
    theClick(b,a){
        const that = this;       
        if(a == 'relative'){
            that.add_edit_show = true;
            that.editForm.contract_id = b.contract_id;
        }else if(a == 'detail'){
            that.$router.push({path:"/contractInfo",name:"/contractInfo",params:{contract_id:b.contract_id}})
        }
    },
    getitem(data){ 
        const that = this;
        that.editForm.project_id = data.project_id      
    }

  }
}
</script>
